
#pragma once

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}
#include <QImage>
#include <QDebug>
#include <QObject>
#include <QByteArray>
#include <QSize>
typedef struct 
{
    QByteArray data;
    QSize size;
} VideoFrame;

class Encoder : public QObject {
public:
    Encoder(QObject *parent = nullptr);
    ~Encoder();
    int initialize(int width, int height,int fps);
    int encodeFrame(QImage& img,int pts,VideoFrame& videoframe);
    void finish();

private:
    int m_width;
    int m_height;
    int m_fps;

    AVCodec *codec = nullptr;
    AVCodecContext *codecCtx = nullptr;
    AVFrame *frame = nullptr;
    AVPacket pkt;

    SwsContext *swsCtx = nullptr;
    
};